package ngamejava2;

public class GameUpdater implements Runnable
{
	private boolean terminated;
	private long currentUpdate;
	private iGameLoopListener updateListener;

	public GameUpdater(iGameLoopListener anUpdateListener)
	{
		setUpdatable(anUpdateListener);
	}

	public GameUpdater()
	{
		this(null);
	}

	public void run()
	{
		currentUpdate = 0;
		terminated = false;
		while (!terminated)
		{
			if (updateListener != null)
			{
				updateListener.gameLoopUpdate(currentUpdate++);
			}
			Thread.yield();
		}
	}

	public void setUpdatable(iGameLoopListener anUpdateListener)
	{
		updateListener = anUpdateListener;
	}

	public void terminate()
	{
		terminated = true;
	}
}
